/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.teacake.filteringproxy;
import java.net.Socket;
import java.net.ServerSocket;
import java.net.Inet4Address;
/**
 *
 * @author tkleisas
 */
public class HttpProxyServer extends Thread
{
    public HttpProxyServer(String netinterface, int port, String logfile) throws Exception
    {

        m_serversocket = new java.net.ServerSocket(port, 256, java.net.InetAddress.getByName(netinterface));
        m_logmanager = new LogManager(logfile);

    }
    @Override
    public void run()
    {
        m_running = true;
        while(m_running)
        {
            try
            {
                Socket newsocket = m_serversocket.accept();
                String logfilename = newsocket.getInetAddress().getHostAddress()+".log";
                Logfile log = m_logmanager.getLogfile(logfilename);

                HttpChannel channel= new HttpChannel(newsocket,log);
                channel.start();

            }
            catch(Exception e)
            {

            }
        }
    }
    public void setRunning(boolean flag)
    {
        m_running = flag;
    }
    private ServerSocket  m_serversocket;
    private boolean m_running;
    private LogManager m_logmanager;
    public static void main(String[] args)
    {

    }
}
